<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class TempInspect extends Model
{
    use HasFactory;

    protected $fillable = ['type','title','floor','images','content','status','project_id','person_id','push_id','days','end_date'];

    const POSTONLY = ['type','title','floor','images','content','status','project_id','person_id','push_id','days','end_date'];

    protected $appends = [
        'status_text','type_text'
    ];

    protected function serializeDate(\DateTimeInterface $date)
    {
        return $date->format($this->dateFormat ?: 'Y-m-d H:i:s');
    }

    public function getStatusTextAttribute()
    {
        return $this->status == 1 ? '维修' : '处罚';
    }

    public function getTypeTextAttribute()
    {
        if($this->type == 'safe'){
            return '安全检查';
        }
        if($this->type == 'quality'){
            return '质量检查';
        }
        return '-';
    }

    public function project()
    {
        return $this->hasOne(Project::class,'id','project_id')->select('id','title','status');
    }

    public function person()
    {
        return $this->hasOne(User::class,'id','person_id')->select('id','name');
    }

    public function user()
    {
        return $this->hasOne(User::class,'id','push_id')->select('id','name');
    }
}
